<template>
  <el-dialog :visible.sync="dialogVisible" :title="'订单认款状态'" :close-on-click-modal="false" width="1200px" v-drag2anywhere>
    <div>
      <el-form :model="formData" ref="formData" label-width="100px">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="订单号:">
              {{formData.ordercode}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单渠道:">
              {{formData.platform}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单总额:">
              {{parseFloat(formData.sum_order).toFixed(2)}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户名:">
              {{formData.buyerinfo.buyer}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="合作商:">
              {{formData.supname}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属账套:">
              {{formData.account}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="业务员:">
              {{formData.saleman}}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <el-form-item label="订单明细:">
              <div style="height: 150px;overflow-y:auto; padding: 1px;">
              <el-table :data="formData.goods" border height="100%">
                <el-table-column type="index" label="序号" width="60px" align="center"></el-table-column>
                <el-table-column prop="title" label="商品名称"></el-table-column>
                <el-table-column prop="model" label="规格型号" width="100px"></el-table-column>
                <el-table-column prop="unit" label="单位" width="100px" align="center"></el-table-column>
                <el-table-column prop="count" label="数量" width="100px" align="center"></el-table-column>
                <el-table-column prop="price" label="单价" width="100px" align="center">
                  <template v-slot="scope">
                    {{scope.row.price|number(2)}}
                  </template>
                </el-table-column>
                <el-table-column prop="total" label="小计" width="100px" align="center">
                  <template v-slot="scope">
                    {{scope.row.total|number(2)}}
                  </template>
                </el-table-column>
              </el-table>
              </div>
              <div style="text-align: right;padding: 2px 0px;border:1px solid #E3E3E3; border-top: none;">
                <span style="margin-right:15px">价税总额:{{formData.sum_order|number(2)}}</span>
              </div>

            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="认款状态">
              <el-select v-model="formData.requestpay_status">
                <el-option label="未认款" value="0"></el-option>
                <el-option label="已认款" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="认款备注:">
              <el-input type="textarea" :rows="4" placeholder="客户发票号或数电号码" v-model="formData.requestpay_memo"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
     <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false" size="medium">取 消</el-button>
      <el-button type="primary" @click="handleSave" size="medium">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>

   import axios from 'axios';
  export default {

    data() {
      return {
        index: -1,
        ouid: '',
        formData: {
          ordercode: '',
          orderdate: '',
          buyerinfo:{
            buyer:''
          },
          requestpay_status:0,
          requestpay_memo:'',
          clientticket_fphm:''
        },

        dialogVisible: true,


      }
    },

    filters: {
      //保留2位小数点过滤器，不四五入
      number(value, n = 3) {
        //var toFixedNum=parseFloat(value).toFixed(n);
        var toFixedNum = parseFloat(value).toFixed(n);
        var realVal = toFixedNum.substring(0, toFixedNum.toString().length);
        return realVal;
      }
    },
    methods: {
      init: function(index, data) {
        this.index = index;
        this.formData = data;
        this.upconfig.imgList=data.clientticket_attach;

      },
      format2Number(value, len) {
        var f = parseFloat(value);
        var f = Math.round(value * 100) / 100;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
          rs = s.length;
          s += '.';
        }
        while (s.length <= rs + len) {
          s += '0';
        }
        return s;
        return realVal;
      },


      handleSave: function() {
        const params={
          ouid:this.formData.ouid,
          status:this.formData.requestpay_status,
          memo:this.formData.requestpay_memo
          }

          this.axios.post("api/admin/order/update_requestpay_status",params).then(res=>{
            if(res.status==200 && res.data.code==1){
               this.$message.success({message:res.data.msg,duration:1500,showClose:true});
               this.dialogVisible=false;
               this.$emit("closeHandler",this.index,this.formData);

            }else{
               this.$message.error({message:res.data.msg,duration:1500,showClose:true});
            }
          })
      },

    }
  }
</script>

<style scoped>
  .el-tag+.el-tag {
    margin-left: 10px;
  }

  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }

  .input-new-tag {
    width: 120px;
    margin-left: 10px;
    vertical-align: bottom;
  }

  .el-upload-list__item .el-icon-close-tip {
    display: none !important;
  }
</style>
